.class public Lcom/instagram/realtimeclient/RealtimeClient;
.super Ljava/lang/Object;
.source "RealtimeClient.java"

# interfaces
.implements Lcom/a/a/h;


# static fields
.field private static final NETWORK_CONNECTIVITY_CHANGE:Ljava/lang/String; = "android.net.conn.CONNECTIVITY_CHANGE"

.field private static final sMapper:Lcom/fasterxml/jackson/databind/ObjectMapper;

.field private static final sMaxBackoffIntervalMs:J

.field private static final sParseExecutor:Ljava/util/concurrent/ExecutorService;

.field private static final sSubscribeTimeoutMs:J


# instance fields
.field private mBackoffIntervalMs:J

.field private final mBroadcastReceiver:Landroid/content/BroadcastReceiver;

.field private mContext:Landroid/content/Context;

.field private mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

.field private mIsBroadcastReceiverRegistered:Z

.field private mPingTimeoutMs:J

.field private final mPingTimeoutRunnable:Ljava/lang/Runnable;

.field private final mRealtimeHandler:Landroid/os/Handler;

.field private final mReconnectRunnable:Ljava/lang/Runnable;

.field private final mRefreshRunnable:Ljava/lang/Runnable;

.field private final mSubscribeTimeoutRunnable:Ljava/lang/Runnable;

.field private mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

.field private mWebSocketClient:Lcom/a/a/d;


# direct methods
.method static constructor <clinit>()V
    .locals 4

    .prologue
    const-wide/16 v2, 0xa

    .line 33
    sget-object v0, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    invoke-virtual {v0, v2, v3}, Ljava/util/concurrent/TimeUnit;->toMillis(J)J

    move-result-wide v0

    sput-wide v0, Lcom/instagram/realtimeclient/RealtimeClient;->sMaxBackoffIntervalMs:J

    .line 35
    sget-object v0, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    invoke-virtual {v0, v2, v3}, Ljava/util/concurrent/TimeUnit;->toMillis(J)J

    move-result-wide v0

    sput-wide v0, Lcom/instagram/realtimeclient/RealtimeClient;->sSubscribeTimeoutMs:J

    .line 40
    new-instance v0, Lcom/fasterxml/jackson/databind/ObjectMapper;

    invoke-direct {v0}, Lcom/fasterxml/jackson/databind/ObjectMapper;-><init>()V

    sput-object v0, Lcom/instagram/realtimeclient/RealtimeClient;->sMapper:Lcom/fasterxml/jackson/databind/ObjectMapper;

    .line 41
    invoke-static {}, Ljava/util/concurrent/Executors;->newSingleThreadExecutor()Ljava/util/concurrent/ExecutorService;

    move-result-object v0

    sput-object v0, Lcom/instagram/realtimeclient/RealtimeClient;->sParseExecutor:Ljava/util/concurrent/ExecutorService;

    return-void
.end method

.method public constructor <init>(Landroid/content/Context;)V
    .locals 3
    .parameter "context"

    .prologue
    .line 99
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 38
    sget-object v0, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    const-wide/16 v1, 0x1e

    invoke-virtual {v0, v1, v2}, Ljava/util/concurrent/TimeUnit;->toMillis(J)J

    move-result-wide v0

    iput-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mPingTimeoutMs:J

    .line 47
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    .line 48
    const-wide/16 v0, 0x0

    iput-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBackoffIntervalMs:J

    .line 50
    new-instance v0, Landroid/os/Handler;

    invoke-direct {v0}, Landroid/os/Handler;-><init>()V

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    .line 51
    new-instance v0, Lcom/instagram/realtimeclient/RealtimeClient$1;

    invoke-direct {v0, p0}, Lcom/instagram/realtimeclient/RealtimeClient$1;-><init>(Lcom/instagram/realtimeclient/RealtimeClient;)V

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mReconnectRunnable:Ljava/lang/Runnable;

    .line 57
    new-instance v0, Lcom/instagram/realtimeclient/RealtimeClient$2;

    invoke-direct {v0, p0}, Lcom/instagram/realtimeclient/RealtimeClient$2;-><init>(Lcom/instagram/realtimeclient/RealtimeClient;)V

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRefreshRunnable:Ljava/lang/Runnable;

    .line 63
    new-instance v0, Lcom/instagram/realtimeclient/RealtimeClient$3;

    invoke-direct {v0, p0}, Lcom/instagram/realtimeclient/RealtimeClient$3;-><init>(Lcom/instagram/realtimeclient/RealtimeClient;)V

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscribeTimeoutRunnable:Ljava/lang/Runnable;

    .line 71
    new-instance v0, Lcom/instagram/realtimeclient/RealtimeClient$4;

    invoke-direct {v0, p0}, Lcom/instagram/realtimeclient/RealtimeClient$4;-><init>(Lcom/instagram/realtimeclient/RealtimeClient;)V

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mPingTimeoutRunnable:Ljava/lang/Runnable;

    .line 80
    new-instance v0, Lcom/instagram/realtimeclient/RealtimeClient$5;

    invoke-direct {v0, p0}, Lcom/instagram/realtimeclient/RealtimeClient$5;-><init>(Lcom/instagram/realtimeclient/RealtimeClient;)V

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBroadcastReceiver:Landroid/content/BroadcastReceiver;

    .line 100
    iput-object p1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mContext:Landroid/content/Context;

    .line 101
    return-void
.end method

.method static synthetic access$000(Lcom/instagram/realtimeclient/RealtimeClient;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 28
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->connect()V

    return-void
.end method

.method static synthetic access$100(Lcom/instagram/realtimeclient/RealtimeClient;)Lcom/instagram/realtimeclient/RealtimeEventHandler;
    .locals 1
    .parameter "x0"

    .prologue
    .line 28
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    return-object v0
.end method

.method static synthetic access$200(Lcom/instagram/realtimeclient/RealtimeClient;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 28
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->disconnect()V

    return-void
.end method

.method static synthetic access$300()Lcom/fasterxml/jackson/databind/ObjectMapper;
    .locals 1

    .prologue
    .line 28
    sget-object v0, Lcom/instagram/realtimeclient/RealtimeClient;->sMapper:Lcom/fasterxml/jackson/databind/ObjectMapper;

    return-object v0
.end method

.method static synthetic access$400(Lcom/instagram/realtimeclient/RealtimeClient;Lcom/instagram/realtimeclient/RealtimeEvent;)V
    .locals 0
    .parameter "x0"
    .parameter "x1"

    .prologue
    .line 28
    invoke-direct {p0, p1}, Lcom/instagram/realtimeclient/RealtimeClient;->handleRealtimeEvent(Lcom/instagram/realtimeclient/RealtimeEvent;)V

    return-void
.end method

.method static synthetic access$500(Lcom/instagram/realtimeclient/RealtimeClient;)Landroid/os/Handler;
    .locals 1
    .parameter "x0"

    .prologue
    .line 28
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    return-object v0
.end method

.method private cancelDelayedRunnables()V
    .locals 2

    .prologue
    .line 231
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mReconnectRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 232
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRefreshRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 233
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscribeTimeoutRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 234
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mPingTimeoutRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 235
    return-void
.end method

.method private connect()V
    .locals 3

    .prologue
    .line 163
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    if-nez v0, :cond_0

    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    if-nez v0, :cond_1

    .line 173
    :cond_0
    :goto_0
    return-void

    .line 167
    :cond_1
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->cancelDelayedRunnables()V

    .line 169
    const/4 v0, 0x0

    new-array v0, v0, [Ljava/lang/Object;

    invoke-static {v0}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;

    move-result-object v0

    .line 170
    new-instance v1, Lcom/a/a/d;

    iget-object v2, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    invoke-virtual {v2}, Lcom/instagram/realtimeclient/RealtimeSubscription;->getURL()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Ljava/net/URI;->create(Ljava/lang/String;)Ljava/net/URI;

    move-result-object v2

    invoke-direct {v1, v2, v0}, Lcom/a/a/d;-><init>(Ljava/net/URI;Ljava/util/List;)V

    iput-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    .line 171
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    invoke-virtual {v0, p0}, Lcom/a/a/d;->a(Lcom/a/a/h;)V

    .line 172
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    invoke-virtual {v0}, Lcom/a/a/d;->b()V

    goto :goto_0
.end method

.method private disconnect()V
    .locals 2

    .prologue
    .line 151
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->cancelDelayedRunnables()V

    .line 153
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    if-eqz v0, :cond_0

    .line 155
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    invoke-virtual {v0}, Lcom/a/a/d;->a()V

    .line 156
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    invoke-virtual {v0}, Lcom/a/a/d;->c()V

    .line 157
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    .line 158
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    sget-object v1, Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;->NOT_CONNECTED:Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;

    invoke-interface {v0, v1}, Lcom/instagram/realtimeclient/RealtimeEventHandler;->onConnectionStatusChanged(Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;)V

    .line 160
    :cond_0
    return-void
.end method

.method private handleRealtimeEvent(Lcom/instagram/realtimeclient/RealtimeEvent;)V
    .locals 3
    .parameter "event"

    .prologue
    .line 192
    instance-of v0, p1, Lcom/instagram/realtimeclient/RealtimePatchEvent;

    if-eqz v0, :cond_1

    .line 193
    check-cast p1, Lcom/instagram/realtimeclient/RealtimePatchEvent;

    .line 194
    .end local p1
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    iget-object v1, p1, Lcom/instagram/realtimeclient/RealtimePatchEvent;->sequence:Ljava/lang/String;

    invoke-virtual {v0, v1}, Lcom/instagram/realtimeclient/RealtimeSubscription;->updateSequence(Ljava/lang/String;)V

    .line 195
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    invoke-interface {v0, p1}, Lcom/instagram/realtimeclient/RealtimeEventHandler;->onPatchEvent(Lcom/instagram/realtimeclient/RealtimePatchEvent;)V

    .line 221
    :cond_0
    :goto_0
    return-void

    .line 196
    .restart local p1
    :cond_1
    instance-of v0, p1, Lcom/instagram/realtimeclient/RealtimeSubscribedEvent;

    if-eqz v0, :cond_2

    .line 197
    const-wide/16 v0, 0x0

    iput-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBackoffIntervalMs:J

    .line 198
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscribeTimeoutRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 200
    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    move-object v0, p1

    check-cast v0, Lcom/instagram/realtimeclient/RealtimeSubscribedEvent;

    iget-object v0, v0, Lcom/instagram/realtimeclient/RealtimeSubscribedEvent;->sequence:Ljava/lang/String;

    invoke-virtual {v1, v0}, Lcom/instagram/realtimeclient/RealtimeSubscription;->updateSequence(Ljava/lang/String;)V

    .line 202
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    sget-object v1, Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;->SUBSCRIBED:Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;

    invoke-interface {v0, v1}, Lcom/instagram/realtimeclient/RealtimeEventHandler;->onConnectionStatusChanged(Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;)V

    .line 204
    check-cast p1, Lcom/instagram/realtimeclient/RealtimeSubscribedEvent;

    .end local p1
    iget-boolean v0, p1, Lcom/instagram/realtimeclient/RealtimeSubscribedEvent;->mustRefresh:Z

    if-eqz v0, :cond_0

    .line 205
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    invoke-interface {v0}, Lcom/instagram/realtimeclient/RealtimeEventHandler;->onFeedRefreshRequested()V

    goto :goto_0

    .line 207
    .restart local p1
    :cond_2
    instance-of v0, p1, Lcom/instagram/realtimeclient/RealtimeUnsubscribedEvent;

    if-eqz v0, :cond_3

    .line 208
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    sget-object v1, Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;->CONNECTED:Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;

    invoke-interface {v0, v1}, Lcom/instagram/realtimeclient/RealtimeEventHandler;->onConnectionStatusChanged(Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;)V

    .line 210
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->sendSubscribeMessage()V

    goto :goto_0

    .line 211
    :cond_3
    instance-of v0, p1, Lcom/instagram/realtimeclient/RealtimeKeepaliveEvent;

    if-eqz v0, :cond_4

    .line 212
    sget-object v0, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    check-cast p1, Lcom/instagram/realtimeclient/RealtimeKeepaliveEvent;

    .end local p1
    iget-wide v1, p1, Lcom/instagram/realtimeclient/RealtimeKeepaliveEvent;->interval:D

    double-to-long v1, v1

    invoke-virtual {v0, v1, v2}, Ljava/util/concurrent/TimeUnit;->toMillis(J)J

    move-result-wide v0

    iput-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mPingTimeoutMs:J

    .line 213
    invoke-virtual {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->onPing()V

    goto :goto_0

    .line 214
    .restart local p1
    :cond_4
    instance-of v0, p1, Lcom/instagram/realtimeclient/RealtimeErrorEvent;

    if-eqz v0, :cond_5

    .line 216
    invoke-virtual {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->unsubscribe()V

    .line 217
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRefreshRunnable:Ljava/lang/Runnable;

    invoke-direct {p0, v0}, Lcom/instagram/realtimeclient/RealtimeClient;->performWithBackoff(Ljava/lang/Runnable;)V

    goto :goto_0

    .line 219
    :cond_5
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "Received unknown message"

    invoke-static {v0, v1}, Lcom/facebook/e/a/a;->a(Ljava/lang/Class;Ljava/lang/String;)V

    goto :goto_0
.end method

.method private performWithBackoff(Ljava/lang/Runnable;)V
    .locals 4
    .parameter "runnable"

    .prologue
    .line 224
    iget-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBackoffIntervalMs:J

    const-wide/16 v2, 0x0

    cmp-long v0, v0, v2

    if-nez v0, :cond_0

    const-wide/16 v0, 0x1f4

    :goto_0
    iput-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBackoffIntervalMs:J

    .line 226
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    invoke-virtual {v0, p1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 227
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-wide v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBackoffIntervalMs:J

    invoke-virtual {v0, p1, v1, v2}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    .line 228
    return-void

    .line 224
    :cond_0
    iget-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBackoffIntervalMs:J

    const-wide/16 v2, 0x2

    mul-long/2addr v0, v2

    sget-wide v2, Lcom/instagram/realtimeclient/RealtimeClient;->sMaxBackoffIntervalMs:J

    invoke-static {v0, v1, v2, v3}, Ljava/lang/Math;->min(JJ)J

    move-result-wide v0

    goto :goto_0
.end method

.method private sendSubscribeMessage()V
    .locals 4

    .prologue
    .line 176
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    if-nez v0, :cond_0

    .line 189
    :goto_0
    return-void

    .line 181
    :cond_0
    :try_start_0
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscribeTimeoutRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 182
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscribeTimeoutRunnable:Ljava/lang/Runnable;

    sget-wide v2, Lcom/instagram/realtimeclient/RealtimeClient;->sSubscribeTimeoutMs:J

    invoke-virtual {v0, v1, v2, v3}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    .line 183
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    sget-object v1, Lcom/instagram/realtimeclient/RealtimeClient;->sMapper:Lcom/fasterxml/jackson/databind/ObjectMapper;

    new-instance v2, Lcom/instagram/realtimeclient/RealtimeSubscribeCommand;

    iget-object v3, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    invoke-direct {v2, v3}, Lcom/instagram/realtimeclient/RealtimeSubscribeCommand;-><init>(Lcom/instagram/realtimeclient/RealtimeSubscription;)V

    invoke-virtual {v1, v2}, Lcom/fasterxml/jackson/databind/ObjectMapper;->writeValueAsString(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Lcom/a/a/d;->a(Ljava/lang/String;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 186
    :catch_0
    move-exception v0

    .line 187
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v1

    const-string v2, ""

    invoke-static {v1, v2, v0}, Lcom/facebook/e/a/a;->a(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/Throwable;)V

    goto :goto_0
.end method


# virtual methods
.method public getSubscription()Lcom/instagram/realtimeclient/RealtimeSubscription;
    .locals 1

    .prologue
    .line 128
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    return-object v0
.end method

.method public onConnect()V
    .locals 5

    .prologue
    .line 243
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "Connected to %s"

    const/4 v2, 0x1

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    iget-object v4, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    invoke-virtual {v4}, Lcom/instagram/realtimeclient/RealtimeSubscription;->getURL()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    invoke-static {v0, v1, v2}, Lcom/facebook/e/a/a;->a(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Object;)V

    .line 244
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    sget-object v1, Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;->CONNECTED:Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;

    invoke-interface {v0, v1}, Lcom/instagram/realtimeclient/RealtimeEventHandler;->onConnectionStatusChanged(Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;)V

    .line 245
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->cancelDelayedRunnables()V

    .line 246
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->sendSubscribeMessage()V

    .line 247
    invoke-virtual {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->onPing()V

    .line 248
    return-void
.end method

.method public onDisconnect(ILjava/lang/String;)V
    .locals 5
    .parameter "code"
    .parameter "reason"

    .prologue
    .line 289
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "Connection closed. Code: %s, reason: %s"

    const/4 v2, 0x2

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    invoke-static {p1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x1

    aput-object p2, v2, v3

    invoke-static {v0, v1, v2}, Lcom/facebook/e/a/a;->a(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Object;)V

    .line 291
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    .line 292
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->cancelDelayedRunnables()V

    .line 294
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    sget-object v1, Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;->NOT_CONNECTED:Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;

    invoke-interface {v0, v1}, Lcom/instagram/realtimeclient/RealtimeEventHandler;->onConnectionStatusChanged(Lcom/instagram/realtimeclient/RealtimeEventHandler$Status;)V

    .line 295
    if-eqz p1, :cond_0

    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mContext:Landroid/content/Context;

    invoke-static {v0}, Lcom/instagram/n/h;->a(Landroid/content/Context;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 296
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mReconnectRunnable:Ljava/lang/Runnable;

    invoke-direct {p0, v0}, Lcom/instagram/realtimeclient/RealtimeClient;->performWithBackoff(Ljava/lang/Runnable;)V

    .line 298
    :cond_0
    return-void
.end method

.method public onError(Ljava/lang/Exception;)V
    .locals 2
    .parameter "error"

    .prologue
    .line 302
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "Error: "

    invoke-static {v0, v1, p1}, Lcom/facebook/e/a/a;->c(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 304
    const/16 v0, -0x3e8

    invoke-virtual {p1}, Ljava/lang/Exception;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {p0, v0, v1}, Lcom/instagram/realtimeclient/RealtimeClient;->onDisconnect(ILjava/lang/String;)V

    .line 305
    return-void
.end method

.method public onMessage(Ljava/lang/String;)V
    .locals 4
    .parameter "message"

    .prologue
    .line 252
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "Received message: %s"

    const/4 v2, 0x1

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    aput-object p1, v2, v3

    invoke-static {v0, v1, v2}, Lcom/facebook/e/a/a;->a(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Object;)V

    .line 256
    sget-object v0, Lcom/instagram/realtimeclient/RealtimeClient;->sParseExecutor:Ljava/util/concurrent/ExecutorService;

    new-instance v1, Lcom/instagram/realtimeclient/RealtimeClient$6;

    invoke-direct {v1, p0, p1}, Lcom/instagram/realtimeclient/RealtimeClient$6;-><init>(Lcom/instagram/realtimeclient/RealtimeClient;Ljava/lang/String;)V

    invoke-interface {v0, v1}, Ljava/util/concurrent/ExecutorService;->execute(Ljava/lang/Runnable;)V

    .line 272
    return-void
.end method

.method public onMessage([B)V
    .locals 0
    .parameter "message"

    .prologue
    .line 277
    return-void
.end method

.method public onPing()V
    .locals 4

    .prologue
    .line 281
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mPingTimeoutRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 282
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mWebSocketClient:Lcom/a/a/d;

    if-eqz v0, :cond_0

    .line 283
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mRealtimeHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mPingTimeoutRunnable:Ljava/lang/Runnable;

    iget-wide v2, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mPingTimeoutMs:J

    invoke-virtual {v0, v1, v2, v3}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    .line 285
    :cond_0
    return-void
.end method

.method public setEventHandler(Lcom/instagram/realtimeclient/RealtimeEventHandler;)V
    .locals 0
    .parameter "eventHandler"

    .prologue
    .line 104
    iput-object p1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mEventHandler:Lcom/instagram/realtimeclient/RealtimeEventHandler;

    .line 105
    return-void
.end method

.method public setSubscription(Lcom/instagram/realtimeclient/RealtimeSubscription;)V
    .locals 2
    .parameter "subscription"

    .prologue
    .line 108
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    if-nez v0, :cond_0

    .line 109
    iput-object p1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    .line 125
    :goto_0
    return-void

    .line 112
    :cond_0
    if-nez p1, :cond_1

    .line 113
    invoke-virtual {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->unsubscribe()V

    .line 114
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    goto :goto_0

    .line 117
    :cond_1
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    invoke-virtual {v0}, Lcom/instagram/realtimeclient/RealtimeSubscription;->getTopic()Ljava/lang/String;

    move-result-object v0

    invoke-virtual {p1}, Lcom/instagram/realtimeclient/RealtimeSubscription;->getTopic()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_2

    .line 119
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    invoke-virtual {v0, p1}, Lcom/instagram/realtimeclient/RealtimeSubscription;->updateWithSubscription(Lcom/instagram/realtimeclient/RealtimeSubscription;)V

    goto :goto_0

    .line 122
    :cond_2
    invoke-virtual {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->unsubscribe()V

    .line 123
    iput-object p1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mSubscription:Lcom/instagram/realtimeclient/RealtimeSubscription;

    goto :goto_0
.end method

.method public subscribe()V
    .locals 4

    .prologue
    .line 132
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "subscribe()"

    invoke-static {v0, v1}, Lcom/facebook/e/a/a;->a(Ljava/lang/Class;Ljava/lang/String;)V

    .line 133
    const-wide/16 v0, 0x0

    iput-wide v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBackoffIntervalMs:J

    .line 134
    iget-boolean v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mIsBroadcastReceiverRegistered:Z

    if-nez v0, :cond_0

    .line 135
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mContext:Landroid/content/Context;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBroadcastReceiver:Landroid/content/BroadcastReceiver;

    new-instance v2, Landroid/content/IntentFilter;

    const-string v3, "android.net.conn.CONNECTIVITY_CHANGE"

    invoke-direct {v2, v3}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0, v1, v2}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;

    .line 136
    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mIsBroadcastReceiverRegistered:Z

    .line 138
    :cond_0
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->connect()V

    .line 139
    return-void
.end method

.method public unsubscribe()V
    .locals 2

    .prologue
    .line 142
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const-string v1, "unsubscribe()"

    invoke-static {v0, v1}, Lcom/facebook/e/a/a;->a(Ljava/lang/Class;Ljava/lang/String;)V

    .line 143
    iget-boolean v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mIsBroadcastReceiverRegistered:Z

    if-eqz v0, :cond_0

    .line 144
    iget-object v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mContext:Landroid/content/Context;

    iget-object v1, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mBroadcastReceiver:Landroid/content/BroadcastReceiver;

    invoke-virtual {v0, v1}, Landroid/content/Context;->unregisterReceiver(Landroid/content/BroadcastReceiver;)V

    .line 145
    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/instagram/realtimeclient/RealtimeClient;->mIsBroadcastReceiverRegistered:Z

    .line 147
    :cond_0
    invoke-direct {p0}, Lcom/instagram/realtimeclient/RealtimeClient;->disconnect()V

    .line 148
    return-void
.end method
